package es.udc.iagolast.androidJam.Activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import es.udc.iagolast.hellogooglemaps.R;

public class MainActivity extends Activity {
SharedPreferences settings;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		settings = getPreferences(MODE_PRIVATE);
	}
	@Override
	public void onResume(){
		super.onResume();
		/*if(settings.getBoolean("running", false)){
			Button button = (Button) findViewById(R.id.button1);
			button.setText(R.string.SeeCurrent);
		}// */
	}
	public void onStop(){
		settings.edit().putBoolean("running", true).commit();
		super.onStop();
	}
	public void onDestroy(){
		settings.edit().putBoolean("running", true).commit();
		super.onDestroy();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		return true;

	}

	/* public void onTestClick(View view) {

		SharedPreferences set = getPreferences(MODE_PRIVATE);
		String[] argumentos = set.getString("1", "No ha pasado nada")
				.split("-");

		Bundle extras = new Bundle();
		extras.putString("Pool", argumentos[0]);
		extras.putString("metros", argumentos[1]);

		Intent intent = new Intent(getApplicationContext(),
				testparameteractivity.class);
		intent.putExtras(extras);
		startActivity(intent);
	}

	public void onEndNightBtnClicked(View view) {
		SharedPreferences settings = getPreferences(MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("1",
				"call#30.30#40.30#I LIKE TRAINS-beer#32.30#12.23#I LIKE CAMELS");
		editor.commit();

		SharedPreferences set = getPreferences(MODE_PRIVATE);
		String[] argumentos = set.getString("1", "No ha pasado nada")
				.split("-");

		Bundle extras = new Bundle();
		extras.putString("Pool", argumentos[0]);
		extras.putString("metros", argumentos[1]);

		Intent intent = new Intent(getApplicationContext(),
				testparameteractivity.class);
		intent.putExtras(extras);
		startActivity(intent);
	}
*/
	public void onBeginNightBtnClicked(View view) {
		displayAlert();
	}

	public void displayAlert() {

		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.Consumelevels,
				android.R.layout.simple_spinner_item);
		// Specify the layout to use when the list of choices appears
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// Apply the adapter to the spinner
		final Spinner spinner = new Spinner(MainActivity.this);
		spinner.setAdapter(adapter);

		AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

		builder.setMessage("Levels of consume:");
		builder.setTitle(R.string.app_name);
		builder.setView(spinner);
		builder.setNeutralButton(android.R.string.ok, new OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				settings.edit().putBoolean("running", true).commit();
				int option = spinner.getSelectedItemPosition();
				Log.d("DBG", "OPTION : " + option);
				Bundle bundle = new Bundle();
				switch (option) {
				case 0:

					bundle.putInt("pollingTime",10000);
					bundle.putString("metros", "20");
					break;
				case 1:

					bundle.putInt("pollingTime",300000);
					bundle.putInt("metros",30);
					break;
				case 2:
					bundle.putInt("pollingTime", 600000);
					bundle.putInt("metros", 35);
					break;
				case 3:
					bundle.putInt("pollingTime", 0);
					bundle.putInt("minDistance", 0);
					break;
					

				}
				Intent intent = new Intent(getApplicationContext(),
						MainMapActivity.class);
				intent.putExtras(bundle);
				Log.d("DBG",
						"Valores de bundle pool: " + bundle.getString("pollingTime")
								+ "Metros" + bundle.getString("minDistance"));
				startActivity(intent);
			}

		});
		builder.show();

	}
	// */
}
